<template>
    <div class="addlocation">
        <el-form
    :model="ruleForm"
    :rules="rules"
    ref="ruleForm"
    label-width="100px"
    class="demo-ruleForm"
  >
    <el-form-item label="地址名称" prop="address">
      <el-input v-model="ruleForm.address"></el-input>
    </el-form-item>
    <el-form-item label="地址经度" prop="longitude">
      <el-input v-model="ruleForm.longitude"></el-input>
    </el-form-item>
    <el-form-item label="地址纬度" prop="latitude">
      <el-input v-model="ruleForm.latitude"></el-input>
    </el-form-item>
    
    
    
    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')"
        >立即创建</el-button
      >
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
    </div>
  
</template>

<script>
import { addLocation } from "@/api/location";

export default {
  data() {
    return {
      ruleForm: {
        address: "",
        longitude: "",
        latitude: "",
      },
      rules: {
        address: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
          
        ],
        
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
            addLocation({
            address:this.ruleForm.address,
            longitude:this.ruleForm.longitude,
            latitude:this.ruleForm.latitude
          }).then((res)=>{
            this.$message({
            message: '添加地址成功',
            type: 'success'
        });

          }).catch((err)=>{
            this.$message({
            message: '警告哦，这是一条警告消息',
            type: 'warning'
        });
          })
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },

  },
//   created(){
//     this.submitForm()
//   }
};
</script>

<style scoped>

.addlocation{
    width: 70%;
    margin: 100px auto;
}

</style>







